﻿@model SelfMadeMillionaire.Web.Infrastructure.ViewModels.MailingList.EditSubscriptionInfoViewModel
@using SelfMadeMillionaire.Web.Infrastructure

<div class="modal-dialog">
        <div class="modal-content">
            @using (Html.BeginForm("EditSubscriptionInfo", "MailingList", FormMethod.Post, new { @class = "form-horizontal" }))
            {
                @Html.HiddenFor(m => m.ID)
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="edit-dialog-label">Subscription</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-sm-10">
                            <div class="form-group">
                                @Html.LabelFor(model => model.Subscription, new { @class = "col-sm-4 control-label" })
                                <div class="col-sm-8">
                                    @Html.DropDownListFor(m => m.Subscription, Model.ProductTypes, new { @class = "form-control" })
                                </div>
                            </div>
                            <div class="form-group" id="divExpDate">
                                @Html.LabelFor(model => model.ExpirationDate, new { @class = "col-sm-4 control-label" })
                                <div class="col-sm-8">
                                    @Html.TextBoxFor(model => model.ExpirationDate, "{0:" + Constants.DATE_FORMAT + "}", new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.ExpirationDate)
                                </div>
                            </div>
                        </div>
                    </div>


                    <script type="text/javascript">

                        $(function () {
                            $("#@Html.IdFor(m => m.ExpirationDate)").datepicker();
	});

                    </script>

                </div>
                <div class="modal-footer">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="pull-right">
                                <input type="submit" class="btn btn-default width80" value="Save" />
                                <a class="btn btn-default width80" data-dismiss="modal">Cancel</a>
                            </div>
                        </div>
                    </div>
                </div>
            }
        </div>
        <!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->


<script type="text/javascript">
    $(document).ready(function () {
        SetExpDate();

        $("input[type='submit']").click(function (e) {
            e.preventDefault();

            var form = $(this).closest("form");

            if ($(form).valid()) {
                $.ajax({
                    url: $(form).attr("action"),
                    type: "POST",
                    data: form.serialize(),
                    cache: false,
                    success: function (result) {
                        if (result.success) {
                            $("#edit-modal-container").modal('hide');
                            refresh();
                        }
                        else
                            $("#edit-modal-container").html(result);
                    }
                });
            }
        });
    });

    $('#Subscription').change(function () {
        SetExpDate();
    });

    function SetExpDate() {
        var val = $("#Subscription").val();
        if (val <= 0)
            $("#divExpDate").css("visibility", "hidden");
        else
            $("#divExpDate").css("visibility", "");
    }
</script>